package io.zcoder.innoway.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.zcoder.innoway.R;
import io.zcoder.innoway.commons.Constants;
import io.zcoder.innoway.models.Dashboard;
import io.zcoder.innoway.widgets.TextViewCustom;

public class EntryBMIFragment extends Fragment {
    public static final float RATIO = 15f;

    @BindView(R.id.percent)
    TextViewCustom mPercent;
    @BindView(R.id.bmi_pointer)
    ImageView mPointer;
    private Dashboard mDashboard;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_entry_bmi_fragment, container, false);
        ButterKnife.bind(this, view);
        Bundle bundle = getArguments();
        mDashboard = bundle.getParcelable(Constants.DASHBOARD_EXTRAS);
        mPercent.setText(String.format(getString(R.string.percent), mDashboard.getBmi() + ""));

        float f = (mDashboard.getBmi() - 18) * RATIO;
        f = f - 90;
        if (f < 0) {
            f = 0;
        }
        if (f > 180) {
            f = 180;
        }
        mPointer.animate().setDuration(500).rotation(f - 90);
        return view;
    }
}
